﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace VRacer.Packets
{
    public class PlayerCrashedPacket : PlayerPacket
    {
        private int _crashX;
        private int _crashY;
        private int _startX;
        private int _startY;
        private int _lostMoves = 1;

        
        public PlayerCrashedPacket()
            : base(PacketType.PlayerCrashed)
        {
            base.Length += 16;
        }

        public PlayerCrashedPacket(PlayerBase player, Point crashPoint, Point startPoint)
            : this()
        {
            _id = player.ID;
            CrashPoint = crashPoint;
            StartPoint = startPoint;
        }

        public Point CrashPoint
        {
            get { return new Point(_crashX, _crashY); }
            set
            {
                _crashX = (int)value.X;
                _crashY = (int)value.Y;
            }
        }

        public int LostMoves
        {
            get { return _lostMoves; }
            set { _lostMoves = value; }
        }

        public Point StartPoint
        {
            get { return new Point(_startX, _startY); }
            set
            {
                _startX = (int)value.X;
                _startY = (int)value.Y;
            }
        }

        public override void Read(System.IO.BinaryReader reader)
        {
            base.Read(reader);

            _id = reader.ReadInt32();
            _crashX = reader.ReadInt32();
            _crashY = reader.ReadInt32();
            _startX = reader.ReadInt32();
            _startY = reader.ReadInt32();
            _lostMoves = reader.ReadInt32();
        }

        public override void Write(System.IO.BinaryWriter writer)
        {
            base.Write(writer);

            writer.Write(_id);
            writer.Write(_crashX);
            writer.Write(_crashY);
            writer.Write(_startX);
            writer.Write(_startY);
            writer.Write(_lostMoves);
        }
    }
}
